<%@page import="entities.User"%>
<%@page import="auxilary.Constants"%>
<%@page import="auxilary.Links"%>
<%@page import="auxilary.Actions"%>
<%@page import="entities.Session"%>
<%@page import="entities.Course"%>
<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255"%>
    
<%
	Course course = (Course)request.getAttribute("course");
	int status = (Integer)request.getAttribute("status");
	boolean clash = (Boolean)request.getAttribute("clash");
	boolean loggedIn = (request.getSession().getAttribute("user")!=null);
	User user = (User)request.getSession().getAttribute("user");
%>
<jsp:include page="/frames/start.jsp" />
	<%=Links.Css.COURSE %>
	<%=Links.Scripts.COURSE %>
<jsp:include page="/frames/frame.jsp" />
		<div class="course<% if (status==1) { %> registered-course<% } %><% if (status==0) { %> in-wishlist-course<% } %>">
			<div class="tops">
				<a class="top" href ="<%=Links.Pages.COURSES_BASE %>">See all courses</a>
			</div>
			
			<h1>Course details</h1>
		   <% if (course == null) { %>
		   	<center><h3>Course doesn't exist</h3></center>
		   <% } else { %>
			<div class="box">
				<div class="left">Name</div>
				<div class="right"><%=course.getName() %></div>
			</div>
			<div class="box">
				<div class="left">Credits</div>
				<div class="right"><%=course.getCredits() %></div>
			</div>
			<div class="box">
				<div class="left">Description</div>
				<div class="right long"><%=course.getDescription() %></div>
			</div>
			<div class="box">
				<div class="left">Spots</div>
				<div class="right"><%=course.getTaken() %>/<%=course.getCapacity() %></div>
			</div>
			<div class="box">
				<div class="left">Group</div>
				<div class="right"><%=Constants.Group.getName(course.getGroupId()) %></div>
			</div>
			<div class="box">
				<div class="left">Time</div>
				<div class="right">
				   <% for (Session listSession : course.getSessions()) { %>
					<%=listSession.getDayAndTimes() %>
					<br /><br />
				   <% } %>
				</div>
			</div>
			<br />
			<div class="box">
				<hr /><br />
				<input type="hidden">
			  <% if ((clash) && (status!=1)) { %>
			  	<center><b>This course clashes with your other courses</b></center><br />
			  <% } %>
			  <% if (loggedIn) {%>
			   <% if (((status==-1) || (status==0)) && (course.getCapacity()-course.getTaken()>0) && (!clash)) { %>
				<input type="button" value="Register to course" onClick="processRequest('<%=Actions.Course.REGISTER %>','<%=course.getId()%>')">
			   <% } if (status==-1) { %>
				<input type="button" value="Add to wish list" onClick="processRequest('<%=Actions.Course.ADD_TO_WISHLIST %>','<%=course.getId()%>')">
			   <% } if (status==0) { %>
				<input type="button" value="Remove from Wishlist" onClick="processRequest('<%=Actions.Course.UNREGISTER %>','<%=course.getId()%>')">
			   <% } if (status==1) { %>				
			   	<input type="button" value="Unregister" onClick="processRequest('<%=Actions.Course.UNREGISTER %>','<%=course.getId()%>')">
			   <% } if ((user.isAdmin()) && (user.getId() == course.getCreator())) { %>
			   	<br />	
			    <a class="delete-course" href="javascript:deleteCourseByName('<%=Actions.Course.DELETE %>','<%=course.getName() %>')">Delete This Course?</a>
			   <% } %>
			  <% } %>
			</div>
		   <% } %>
		</div>
<jsp:include page="/frames/end.jsp" />